using System;
using System.Collections.Generic;
using System.Text;
using GeneratorLibrary.Client.Base;
using System.Data;

namespace GeneratorLibrary.Client.iSeries {
    public class iSeriesCrudColumn : CrudColumnBase {
        public iSeriesCrudColumn(DataRow row) : base(row) { }

        public override string GetDefaultCoalesce() {
            switch (DataType.ToLower()) {
                case "bigint":
                case "decimal":
                case "decfloat":
                case "double":
                case "numeric":
                case "float":
                case "int":
                case "integer":
                case "real":
                case "smallint":
                    return "0";
                case "date":
                    return "current date";
                case "time":
                    return "current time";
                case "timestmp":
                    return "current timestamp";
                default:
                    return "''";
            }
        }

        protected override string getQualifiedDataType() {
            switch (this.DataType.ToLower()) {
                case "float":
                    return this.DataType + "(" + this.NumericPrecision.ToString() + ")";
                case "decimal":
                case "numeric":
                    return this.DataType + "(" + this.NumericPrecision.ToString() + "," + this.NumericScale.ToString() + ")";
                case "char":
                case "varchar":
                case "binary":
                case "blob":
                case "clob":
                case "datalink":
                case "dbclob":
                case "graphic":
                    return this.DataType + "(" + this.Length.ToString() + ")";
                //iseries doesn't like it if you use the iseries appreviated type names that it stores
                case "varg":
                    return "VARGRAPHIC(" + this.Length.ToString() + ")";
                case "varbin":
                    return "VARBINARY(" + this.Length.ToString() + ")";
                case "timestmp":
                    return "TIMESTAMP";
                default:
                    return this.DataType;
            }
        }
    }
}
